﻿using System;
using Ewk.Math.Algebra.UnitTests.MatrixTests.NumericTests;
using Ewk.Math.ComputationTypes;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ewk.Math.Algebra.UnitTests.MatrixSearchTests
{
    public abstract class GetNumberOfZeroEntriesInRowTestBase<T> : NumericTestBase<T>
        where T : struct, IComparable, IFormattable, IConvertible, IComparable<T>, IEquatable<T>
    {
        protected override Matrix<T> Matrix
        {
            get
            {
                return CreateMatrix(new[,]
                    {
                        {Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, },
                        {Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, },
                        {Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, },
                        {Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, },
                    });
            }
        }

        [TestMethod]
        public void When_a_matrix_contains_no_zeroes_in_any_of_its_rows_Then_GetNumberOfZeroEntriesInRow_returns_0_for_all_rows()
        {
            for (var i = 0; i < Matrix.RowCount; i++)
            {
                var count = Matrix.GetNumberOfZeroEntriesInRow(i);
                Assert.AreEqual(0, count);
            }
        }

        [TestMethod]
        public void When_a_matrix_contains_one_zero_in_the_first_row_Then_GetNumberOfZeroEntriesInRow_returns_1()
        {
            var matrix = Matrix;
            matrix[0, 0] = Computable<T>.Factory.Zero.Value;

            var i = matrix.GetNumberOfZeroEntriesInRow(0);
            Assert.AreEqual(1, i);
        }

        [TestMethod]
        public void When_a_matrix_contains_two_zeroes_in_the_first_row_Then_GetNumberOfZeroEntriesInRow_returns_2()
        {
            var matrix = Matrix;
            matrix[0, 0] = Computable<T>.Factory.Zero.Value;
            matrix[0, 1] = Computable<T>.Factory.Zero.Value;

            var i = matrix.GetNumberOfZeroEntriesInRow(0);
            Assert.AreEqual(2, i);
        }

        [TestMethod]
        public void When_a_matrix_contains_three_zeroes_in_the_first_row_Then_GetNumberOfZeroEntriesInRow_returns_3()
        {
            var matrix = Matrix;
            matrix[0, 0] = Computable<T>.Factory.Zero.Value;
            matrix[0, 1] = Computable<T>.Factory.Zero.Value;
            matrix[0, 3] = Computable<T>.Factory.Zero.Value;

            var i = matrix.GetNumberOfZeroEntriesInRow(0);
            Assert.AreEqual(3, i);
        }
    }
}